#!/bin/bash

cat << "EOF"
================================================
    建党在线系统 - 重新构建 Docker 镜像
================================================
EOF

echo ""
echo "📂 当前目录: $(pwd)"
echo ""
echo "🛑 停止并删除旧容器..."
docker compose down

echo ""
echo "🗑️  删除旧镜像..."
docker rmi jian-dang-online-client jian-dang-online-front jian-dang-online-backend 2>/dev/null || true

echo ""
echo "🔨 重新构建所有镜像..."
docker compose build --no-cache

if [ $? -eq 0 ]; then
    echo ""
    echo "✅ 构建成功！"
    echo ""
    echo "🚀 启动所有服务..."
    docker compose up -d
    
    if [ $? -eq 0 ]; then
        echo ""
        echo "================================================"
        echo "✅ 服务启动成功！"
        echo "================================================"
        echo ""
        echo "📱 访问地址："
        echo "   管理端: http://localhost:8088"
        echo "   用户端: http://localhost:8089"
        echo "   后端API: http://localhost:8080/springboot1i659/"
        echo ""
        echo "📋 查看日志："
        echo "   docker compose logs -f"
        echo ""
        echo "================================================"
    else
        echo ""
        echo "❌ 启动失败，请检查错误信息"
    fi
else
    echo ""
    echo "❌ 构建失败，请检查错误信息"
fi

echo ""
echo "按 Enter 键关闭此窗口..."
read

